package ldh.im.base.handler;

import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import ldh.im.dto.business.P2pTextMessage;
import ldh.im.dto.base.SuccessResp;
import ldh.im.util.JsonUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@ChannelHandler.Sharable
public class TextMessageHandler extends SimpleChannelInboundHandler<P2pTextMessage> {

    private static final Logger LOGGER = LoggerFactory.getLogger(TextMessageHandler.class);

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, P2pTextMessage msg) throws Exception {
        LOGGER.info(String.format("receive message:" + JsonUtil.toJson(msg)));

        ctx.channel().writeAndFlush(new SuccessResp(msg.getLocalSeq()));
    }
}
